warnings.filterwarnings('ignore', 'apt API not stable yet', FutureWarning)
from mimetypes import guess_type
import apt
import apt_pkg
from DebPackage import DebPackage, Cache
import gettext
def _(str):
return utf8(gettext.gettext(str))
def utf8(str):
if isinstance(str, unicode):
return str
try:
return unicode(str, 'UTF-8')
except:
isinstance(str, unicode)
return unicode(str, 'latin1')
class GDebiCommon(object):
def __init__(self, datadir, options, file = ''):
self.cprogress = None
self.deps = ''
self.version_info_title = ''
self.version_info_msg = ''
self._deb = None
self._options = options
self.install = []
self.remove = []
self.unauthenticated = 0
def openCache(self):
self._cache = Cache(self.cprogress)
if self._cache._depcache.BrokenCount > 0:
self.error_header = _('Broken dependencies')
self.error_body = _("Your system has broken dependencies. This application can not continue until this is fixed. To fix it run 'gksudo synaptic' or 'sudo apt-get install -f' in a terminal window.")
return False
return True
def open(self, file):
try:
self._deb = DebPackage(self._cache, file)
except (IOError, SystemError):
e = None
mimetype = guess_type(file)
if mimetype[0] != None and mimetype[0] != 'application/x-debian-package':
self.error_header = _("'%s' is not a Debian package") % os.path.basename(file)
self.error_body = _("The MIME type of this file is '%s' and can not be installed on this system.") % mimetype[0]
return False
self.error_header = _("Could not open '%s'") % os.path.basename(file)
self.error_body = _('The package might be corrupted or you are not allowed to open the file. Check the permissions of the file.')
return False
except:
mimetype[0] != 'application/x-debian-package'
def compareDebWithCache(self):
res = self._deb.compareToVersionInCache(useInstalled = False)
if not (self._options.non_interactive) and res != DebPackage.NO_VERSION:
pkg = self._cache[self._deb.pkgName]
if res == DebPackage.VERSION_SAME:
if self._cache.downloadable(pkg, useCandidate = True):
self.version_info_title = _('Same version is available in a software channel')
self.version_info_msg = _('You are recommended to install the software from the channel instead.')
elif res == DebPackage.VERSION_IS_NEWER:
if self._cache.downloadable(pkg, useCandidate = True):
self.version_info_title = _('An older version is available in a software channel')
self.version_info_msg = _('Generally you are recommended to install the version from the software channel, since it is usually better supported.')
elif res == DebPackage.VERSION_OUTDATED:
if self._cache.downloadable(pkg, useCandidate = True):
self.version_info_title = _('A later version is available in a software channel')
self.version_info_msg = _('You are strongly advised to install the version from the software channel, since it is usually better supported.')